const { cleanDatEnglishText } = require("../src/utils/datTextCleaner");

// 测试用例
const testCases = [
  // 基本的重复词测试
  {
    input: "Please$please$$$$$ ^give$give$$$$$ ^our$our$$$$$ ^claim$claim$$$$$ ^your$your$$$$$ ^favorable$favorable$$$$$^",
    expected: "Please give our claim your favorable",
  },
  // 词组重复测试
  {
    input: "due to$due to$$$$$ ^omission$omission$$$$$",
    expected: "due to omission",
  },
  // 复杂词组重复测试
  {
    input: "as soon as possible$as soon as possible$$$$$",
    expected: "as soon as possible",
  },
  // in view of 重复测试
  {
    input: "in view of$in view of$$$$$ ^our$our$$$$$ ^friendly$friendly$$$$$",
    expected: "in view of our friendly",
  },
  // turn out 重复测试
  {
    input: "turn out$turn out$$$$$ ^to$to$$$$$ ^your$your$$$$$ ^satisfaction$satisfaction$$$$$",
    expected: "turn out to your satisfaction",
  },
  // 完整句子测试 (注意：缩写会被自动转换)
  {
    input:
      "We$we$$$$$ ^are$are$$$$$ ^sorry$sorry$$$$$ ^that$that$$$$$ ^the$the$$$$$ ^quality$quality$$$$$ ^of$of$$$$$ ^our$our$$$$$ ^goods$goods$$$$$ ^did$did$$$$$ ^not$not$$$$$ ^turn out$turn out$$$$$ ^to$to$$$$$ ^your$your$$$$$ ^satisfaction$satisfaction$$$$$",
    expected: "We are sorry that the quality of our goods didn't turn out to your satisfaction",
  },
  // 多个重复词组测试 (注意：大小写会保持原始格式)
  {
    input:
      "In view of$In view of$$$$$ ^our$our$$$$$ ^friendly$friendly$$$$$ ^business$business$$$$$ ^relations$relation$$$$$ ^we$we$$$$$ ^are$are$$$$$ ^prepared$prepared$$$$$ ^to$to$$$$$ ^meet$meet$$$$$ ^your$your$$$$$ ^claim$claim$$$$$ ^for$for$$$$$ ^the$the$$$$$ 25 ^tons$ton$$$$$ ^shortage$shortage$$$$$ ^weight$weight$$$$$",
    expected: "In view of our friendly business relations we are prepared to meet your claim for the 25 tons shortage weight",
  },
];

console.log("开始测试DAT文本清理工具...\n");

let passedTests = 0;
let totalTests = testCases.length;

testCases.forEach((testCase, index) => {
  const result = cleanDatEnglishText(testCase.input);
  const passed = result === testCase.expected;

  console.log(`测试 ${index + 1}: ${passed ? "通过" : "失败"}`);
  console.log(`  输入: ${testCase.input}`);
  console.log(`  期望: ${testCase.expected}`);
  console.log(`  实际: ${result}`);
  console.log("");

  if (passed) {
    passedTests++;
  }
});

console.log(`测试结果: ${passedTests}/${totalTests} 个测试通过`);

if (passedTests === totalTests) {
  console.log("所有测试通过！DAT文本清理工具工作正常。");
} else {
  console.log("部分测试失败，请检查实现。");
}
